<style>
  .error {color : red}
</style>
<div class="container-fluid p-t-10">
  <ol class="breadcrumb" style="font-weight: 700;margin-bottom: 10px">
    <li><a href="#">节点管理</a></li>
    <li class="active">新增节点</li>
  </ol>
  <div class="row">
    <div class="col-lg-12">
      <div class="card">

        <div class="card-body">
          <h1>{$data?'修改':'新增'}节点</h1>
          <form id="add-form" action="{$url}" method="post" class="row">
            <div class="form-group col-md-12 {$data? '':'hide'}">
              <label for="id">节点编号</label>
              <input type="text" class="form-control" id="id" name="id" readonly value="{$data? $data.id:''}"/>
            </div>

            <div class="form-group col-md-12">
              <label for="path_name">节点名称</label>
              <input type="text" class="form-control" id="path_name" name="path_name" value="{$data? $data.path_name:''}" placeholder="请输入节点名称 例如: 节点管理" />
            </div>
            <div class="form-group col-md-12">
              <label for="path">节点路径</label>
              <input type="text" class="form-control" id="path" name="path" value="{$data? $data.path:''}" placeholder="请输入路径 例如: /path/index" />
            </div>

            <div class="form-group col-md-12">
              <button type="submit" class="btn btn-primary ajax-post" target-form="add-form">确 定</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
<script>

  $(function(){
    $("#add-form").validate({
      rules: {
          path_name: {
          required: true,
          remote:{
            url: '/path/checkName',
            type: "post",               //数据发送方式
            dataType: "json",           //接受数据格式
            data: {                     //要传递的数据
                'path_name': function() {
                return $("#path_name").val();
              },
              id:function() {
                var $id = $("#id");
                if($id.length > 0){
                  return $id.val();
                }
                return 0;
              },
            }
          }
        }
      },
      messages: {
          path_name:{
          remote:'节点名重复'
        }
      },
    });
  });
</script>


